package com.zhiying.server.util;

import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONObject;
import java.io.IOException;

/**
 * @program: Health_Parent
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2020-11-27 15:23
 */
public class BaidCensorUtil {
    //设置APPID/AK/SK
    public static final String APP_ID = "17214730";
    public static final String API_KEY = "WnrcZnQNbveI7UG7sDroOm1K";
    public static final String SECRET_KEY = "FUui3jN440l9eLN8B335C3VS62HvtafU";
    // 初始化一个AipContentCensor
    private static AipContentCensor client;
    static {
        client= new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000); //连接2秒时间超出
        client.setSocketTimeoutInMillis(60000);  //通信6秒时间超出
    }
    //图片审核
    public static boolean consorImg(byte[] data){
        JSONObject res = client.imageCensorUserDefined(data,null);
        if("合规".equals(res.getString("conclusion"))){
            return true;
        }else {
            return false;
        }
    }
    //文本审核
    public static boolean consirText(String msg){
        JSONObject res = client.textCensorUserDefined(msg);
        System.out.println(res);
        if("合规".equals(res.getString("conclusion"))){
            return true;
        }
        return false;
    }

}
